package xyz.hujf.tool.autoclass;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.LongBinaryOperator;

/**
 * @author Hujf
 * @title: LongAccumulator
 * @date 2021-04-27 16:24
 * @description: TODO
 */
public class LongAccumulatorTest {
    private static CountDownLatch count = new CountDownLatch(10);
    public static void main(String[] args) {
        LongAdder adder = new LongAdder();
        List a = new ArrayList(10);
        LongAccumulator accumulator = new LongAccumulator(new LongBinaryOperator() {
            @Override
            public long applyAsLong(long left, long right) {
                return left+right;
            }
        },0);

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                for (int j = 0; j < 1000; j++) {

                }
                count.countDown();
            }).start();
        }
        System.out.println(accumulator.intValue());
    }
}
